home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Documents / OOPClass / Labs / RPNCalculator / Solution / RPNCalculator.m < prev    next >
Encoding:
Text File  |  1992-08-11  |  1.0 KB  |  71 lines

  1. /*Objective_C Implementation of the RPNCalculator Class: RPNCalculator.m*/
  2.  
  3. #import <stdio.h>
  4. #import "RPNCalculator.h"
  5.  
  6. @implementation RPNCalculator
  7.  
  8.  //Initialize a new RPNCalculator instance
  9. -init
  10. {
  11.     stack = [[Stack alloc] init];
  12.     return [super init];
  13. }    
  14.                                                                    
  15. // Enter a number
  16. -(float)enter:(float)number
  17. {
  18.     [stack push:number];
  19.     return [stack top];
  20. }
  21.  
  22. //Add new entry
  23. -(float)add:(float)number
  24. {
  25.     [stack push:number];
  26.     return [self add];
  27. }
  28.  
  29. //Add two elements
  30. -(float)add
  31. {
  32.     [stack push: ( [stack  pop] +  [stack  pop]) ];
  33.     return [stack top];
  34. }
  35.  
  36. //Subtract new entry
  37. -(float)subtract:(float)number
  38. {
  39.     [stack push:number];
  40.     return [self subtract];
  41. }
  42.  
  43. //Subtract two elements
  44. -(float)subtract
  45. {
  46.     [stack push: ( -[stack  pop] +  [stack  pop]) ];
  47.     return [stack top];
  48. }
  49.  
  50. // Print the calculator's stack
  51. -printStack
  52. {
  53.     [stack printStack];
  54.     return self;
  55. }
  56.  
  57. // Empty the calculator's stack
  58. -allClear
  59. {
  60.     [stack empty];
  61.     return self;
  62. }
  63.  
  64. // Free the calculator and its  stack
  65. -free
  66. {
  67.     [stack free];
  68.     return [super free];
  69. }
  70. @end
  71.